#include <iostream>
using namespace std;

/*
    【题目243】编写一个程序，用成员函数重载运算符的方法，使对实型的运算符=、+、*、／适用于复数运算。
    【题目244】编写-个程序，重载插入符>>和提取符<<，使这两种运算符对于复数也可以直接进行操作。
*/

class Complex
{
public:
    Complex(int r, int i) : real(r), imag(i) {}
    Complex operator+(const Complex &c)
    {
        return Complex(real + c.real, imag + c.imag);
    }
    Complex operator-(const Complex &c)
    {
        return Complex(real - c.real, imag - c.imag);
    }
    Complex operator*(const Complex &c)
    {

        return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real);
    }
    Complex operator/(const Complex &c)
    {
        return Complex((real * c.real + imag * c.imag) / (c.real * c.real + c.imag * c.imag),
                       (imag * c.real - real * c.imag) / (c.real * c.real + c.imag * c.imag));
    }
    Complex operator=(const Complex &c)
    {
        real = c.real;
        imag = c.imag;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const Complex &c)
    {
        os << c.real << " + " << c.imag << "i";
        return os;
    }

    friend istream &operator>>(istream &is, Complex &c)
    {
        is >> c.real >> c.imag;
        return is;
    }

    void display()
    {
        cout << real << " + " << imag << "i" << endl;
    }

private:
    int real;
    int imag;
};

int main()
{
    Complex c1(1, 2);
    Complex c2(3, 4);
    Complex c3 = c1 + c2;
    Complex c4 = c1 - c2;
    Complex c5 = c1 * c2;
    Complex c6 = c1 / c2;
    c3.display();
    c4.display();
    c5.display();
    c6.display();

    Complex c7(0, 0);
    cin >> c7;
    cout << c7 << endl;
}